#ifndef _BUSPROTOCOL_H
#define _BUSPROTOCOL_H

#include "SlaveCard.h" 

 

typedef enum
{
  PRO_OK       = 0x00,
  PRO_ERROR    = 0x01,
  PRO_BUSY     = 0x02,
  PRO_TIMEOUT  = 0x03
}PRO_StatusTypeDef;





typedef union _CmdCtlStu
{
	struct
	{ 
		unsigned CtlCmd      		 :4;	
		unsigned SerialCode  		 :2;	
		unsigned reserve  			 :12;	
	} Cmd;
	struct
	{ 
		unsigned CtlCmd      		 :4;	
		unsigned SerialCode  		 :2;	
		unsigned CtlEndIndex  	 :12;	
	} CmdReadEnd;
 	struct
	{ 		
		unsigned CtlCmd      		 :4;	
		unsigned SerialCode  		 :2;	
		unsigned Para	      		 :4;	
		unsigned value      		 :8;	
	} CmdCtl;   
 	struct
	{ 		
		unsigned CtlCmd      		 :4;	
		unsigned SerialCode  		 :2;	
		unsigned reg	 	  	     :4;	
		unsigned value	   		   :8;	
	} CmdReg;   
	unsigned int		AllBits;
}CmdCtlUn;

//×´Ì¬×ÜÏß ºÍÊý¾Ý×ÜÏßÊý¾Ý½á¹¹
typedef union _DataStatusStu
{
	struct
	{ 
		unsigned SerialCode     :2;	
		unsigned cmd    	  	  :3;	
		unsigned DataNum        :2;	
		unsigned Data1          :12;
		unsigned Data2          :12;
	} RxData; 
	struct
	{
		unsigned CtlCmd      		:4;	
		unsigned SerialCode  		:2;	
		unsigned ret    				:2;	
		unsigned value1      		:8;	
		unsigned value2    			:16;
	} CmdAck; 
	struct
	{
		unsigned CtlCmd      		:4;	
		unsigned SerialCode  		:2;	
		unsigned ret    				:2;	
		unsigned value1      		:12;
		unsigned value2    			:12;
	} DataAck; 
	struct
	{
		unsigned StatusBus      :16;
		unsigned DataBus        :16;
	} DataStatusBus; 
	unsigned int AllBits;
}DataStatBusUn;



typedef union _EndDinStu
{
	struct 
	{
		 unsigned b0:1;
		 unsigned b1:1;
		 unsigned b2:1;
		 unsigned b3:1;
		 unsigned b4:1;
		 unsigned b5:1;
		 unsigned b6:1;
		 unsigned b7:1;
		 unsigned b8:1;	
		 unsigned b9:1;		
		 unsigned b10:1;
		 unsigned b11:1;
		 unsigned b12:1;
		 unsigned b13:1;
		 unsigned b14:1;
		 unsigned b15:1;	
	 }oneBit;
	unsigned short allBits;
}Bus16Stu;

typedef union _DataStatusBusStu
{
	struct
	{
		unsigned status     :16;	  
		unsigned data       :16;	
	} Bus; 
	unsigned int All32;
}Bus32Stu;





PRO_StatusTypeDef	SlaveCardDisCharge(void);
unsigned short		GetEndData( unsigned  short *data);	//实现对单个START PIN 扫描，获取结果
PRO_StatusTypeDef	ReadEnd(unsigned  short addr,unsigned  short *data,unsigned  short	len);

#endif
